package sg.edu.nus.iss.cats.action;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import sg.edu.nus.iss.cats.model.*;
import sg.edu.nus.iss.cats.controller.*;
import sg.edu.nus.iss.cats.dataaccess.*;

public class UserListAction extends Action {

    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
                         throws DAOException {

        System.out.println("ListUsersAction");
        UserManager userMgr = new UserManager();
        User[] users = userMgr.findAllUsers();
        
        for (int i=0;i<users.length;i++){
        
            Role[] roles = users[i].getRoles();
            System.out.println("User" + users[i].getName() + " roles len: " +roles.length);
            for (int j=0;j<roles.length;j++){
                System.out.println("got role" + roles[j].getName());
            }
        }
        request.setAttribute("users", users);
        System.out.println("showUsers successful");
        return mapping.findForward("userList");
    }
}